<?php

use Phalcon\Mvc\View;
use Phalcon\Translate\Adapter\NativeArray;

$view = new View();

$view->registerEngines( array(
    '.phtml' => 'volt'
) );

$view->setLayoutsDir( $config->application->layoutDir );
$view->setPartialsDir( $config->application->partialDir );
$view->setTemplateAfter( 'main' );

// Ask browser what is the best language
$chosenLanguage = $di->getSession()->language;
$language = isset( $chosenLanguage ) ? $chosenLanguage : $di->getRequest()->getBestLanguage();

// Check if we have a translation file for that lang
if( file_exists( APP_DIR .'languages/' . $language . '.php' ) )
{
    require APP_DIR .'languages/' . $language . '.php';
}
else
{

// Fallback to some default
    require APP_DIR .'languages/EN_en.php';
}
// Return a translation object
$view->t = new NativeArray( array(
    "content" => $messages
        ) );

return $view;
